<template>
  <div>
    <el-menu
      :default-active="defaultActive"
      router
      unique-opened
      active-text-color="#29A7FA"
      text-color="#5C739F"
       background-color="#fff"
    >
      <div class="user-menu-box" v-for="(item) in menuList">
        <el-submenu v-if="item.child && item.child.length>0" :key="item.id" :index="item.path">
          <template slot="title">
            <i class="left_icon iconfont" :class="item.icon"></i>
            <span>{{item.name}}</span>
          </template>
          <MenuSun :menuList="item.child" />
        </el-submenu>
        <el-menu-item v-else :key="item.id" :index="item.path">
          <i class="left_icon iconfont" :class="item.icon"></i>
          <span>{{item.name}}</span>
        </el-menu-item>
      </div>
    </el-menu>
  </div>
</template>

<script>
  export default {
    name: "MenuSun", //必须要 递归组件的关键，并且要与引入组件的变量名称一致
    props: {
      menuList: {
        type:Array,
        default:[]
      },
    },
    computed:{
      // 获取路由,（监听菜单的改变）
      defaultActive(){
        if(this.$route.path == '/') {
          return 'daibanZX'
        }
        return this.$route.path
      }
    },
    methods:{

    }
  };
</script>
<style type="text/css">
  @import url("../../assets/css/index.css");

  /* //设置侧边栏父级菜单高亮 */
  .el-submenu.is-active > .el-submenu__title {
    color: #29A7FA !important;
  }
  .el-submenu.is-active > .el-submenu__title > i{
    color: #29A7FA!important;
  }
  .el-submenu .el-menu{
    padding-left: 15px;
  }
</style>
